﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Algobox.JuicyLib.SQL.QuantumEdge
{
    public class QEHelper
    {
        public QEHelper(string dbConnString)
        {
            m_Linq = new LinqQuantumEdgeDataContext(dbConnString);
        }

        LinqQuantumEdgeDataContext m_Linq;




        /// <summary>
        /// Inserts a new price entry for a given stock security into the QE database
        /// </summary>
        /// <param name="listing"></param>
        /// <param name="date"></param>
        /// <param name="price"></param>
        /// <param name="overwrite"></param>
        /// <returns></returns>
        public bool TryImportOHLC(Algobox.JuicyLib.Apps.ChiX.ChiXListing listing, DateTime date, Algobox.JuicyLib.MarketData.Structure.OHLC price, bool overwrite)
        {
            int multiplier = 1;
            if (listing.Currency == "GBP")
            {
                listing.Currency = "GBX";
                multiplier = 100;
            }
            lock (m_Linq)
            {
                return m_Linq.ImportOHLC(listing.UMTF,
                    listing.MarketMIC,
                    listing.Currency,
                    listing.ISIN,
                    null,
                    listing.RICPrimary,
                    listing.BBGPrimary,
                    date,
                    price.Open * multiplier,
                    price.High * multiplier,
                    price.Low * multiplier,
                    price.Close * multiplier,
                    price.Volume,
                    overwrite)
                        >= 0;
            }
        }

        
    }
}
